clear;

loaddata=1

switch loaddata
    case 2
        cd 'C:\_bcoe\data_eyelink2\study_1\_C_DATA'
        load eyelink_l.mat
        fig_adj=20; fig_names='EyeLab data (long)';
    case 3
        cd 'C:\_bcoe\data_eyelink2\study_1\_C_DATA'
        load eyelink_s.mat
        eyelink=eyelink2;
        fig_adj=30;fig_names='EyeLab data (short)';        
    case 4
        cd 'C:\_bcoe\data_eyelink2\study_1\_C_DATA'
        load eyelink_all.mat
        fig_adj=40;fig_names='EyeLab data (all)';        
    case 1        
        cd 'C:\_London fMRI Data\C_data'
        load london.mat
        eyelink=london;
        fig_adj=10;fig_names='fMRI data (long)';
end
eyelink.error=double(eyelink.error)
eyelink.error(eyelink.srt>800 & eyelink.error<1)=.2;

anti_pro_peri=[];%(sub_num,:)=fred(1,:,sub_num)-fred(2,:,sub_num);
anti_pro_cent=[];%(sub_num,:)=fred(3,:,sub_num)-fred(4,:,sub_num);
gapfred=[];
bigfred=[];
fig(1+fig_adj);clf; set(gcf,'name',fig_names)
for sub_num=1:length(eyelink.subject)
    subplot(3,3,sub_num);hold on;
    title(eyelink.subject(sub_num,:))
errorbar(0:.5:1, ...
   [mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.0 & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==1))...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.5 & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==1))...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==1.0 & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==1))], ...
   [ ste(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.0 & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==1))...
     ste(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.5 & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==1))...
     ste(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==1.0 & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==1))],'r-o' );
text(.75,.95,['peri-anti (n=' num2str(length(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==1))) ')'],'color','r','units','normalized')

errorbar(0:.5:1, ...
   [mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.0 & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==1))...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.5 & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==1))...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==1.0 & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==1))], ...
   [ ste(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.0 & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==1))...
     ste(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.5 & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==1))...
     ste(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==1.0 & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==1))],'b-o' );
text(.75,.85,['peri-pro  (n=' num2str(length(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==1))) ')'],'color','b','units','normalized')

errorbar(0:.5:1, ...
   [mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.0 & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==0))...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.5 & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==0))...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==1.0 & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==0))], ...
   [ ste(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.0 & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==0))...
     ste(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.5 & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==0))...
     ste(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==1.0 & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==0))],'m-o' );
text(.75,.75,['cent-anti (n=' num2str(length(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==0))) ')'],'color','m','units','normalized')

errorbar(0:.5:1, ...
   [mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.0 & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==0))...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.5 & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==0))...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==1.0 & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==0))], ...
   [ ste(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.0 & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==0))...
     ste(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.5 & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==0))...
     ste(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==1.0 & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==0))],'c-o' );
text(.75,.65,['cent-pro  (n=' num2str(length(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==0))) ')'],'color','c','units','normalized')
set(gca,'XTick',[0:.5:1]);
%ylim([325 875])

  bigfred(:,:,sub_num)=[...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.0 & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==1))...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.5 & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==1))...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==1.0 & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==1)); ...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.0 & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==1))...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.5 & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==1))...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==1.0 & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==1));...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.0 & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==0))...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.5 & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==0))...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==1.0 & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==0)); ...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.0 & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==0))...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==0.5 & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==0))...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & eyelink.delay==1.0 & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==0))]; 

  gapfred(:,:,sub_num)=[...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & (eyelink.delay==0.5 | eyelink.delay==1.0) & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==1));...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & (eyelink.delay==0.5 | eyelink.delay==1.0) & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==1));...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & (eyelink.delay==0.5 | eyelink.delay==1.0) & eyelink.anti==1 & eyelink.error==0 & eyelink.peri==0));...
    mean(eyelink.srt(eyelink.subjectnum==sub_num & (eyelink.delay==0.5 | eyelink.delay==1.0) & eyelink.anti==0 & eyelink.error==0 & eyelink.peri==0))];

anti_pro_peri(sub_num,:)=bigfred(1,:,sub_num)-bigfred(2,:,sub_num);
anti_pro_cent(sub_num,:)=bigfred(3,:,sub_num)-bigfred(4,:,sub_num);
gap_anti_pro_peri(sub_num,:)=gapfred(1,:,sub_num)-gapfred(2,:,sub_num);
gap_anti_pro_cent(sub_num,:)=gapfred(3,:,sub_num)-gapfred(4,:,sub_num);

end
if isnan(bigfred(2,3,2)) %for joanna
bigfred(2,3,2)=mean(bigfred([1 3 4],3,2));
anti_pro_peri(2,:)=bigfred(1,:,2)-bigfred(2,:,2);
anti_pro_cent(2,:)=bigfred(3,:,2)-bigfred(4,:,2);
end

fig(2+fig_adj);clf; set(gcf,'name',fig_names)

temp1=mean(bigfred,3);
temp2=ste(bigfred,0,3);
subplot(2,1,1);hold on;set(gca,'XTick',[0:.5:1]);title('Peripherial')

errorbar(0:.5:1,temp1(1,:),temp2(1,:),'r-s');
errorbar(0:.5:1,temp1(2,:),temp2(2,:),'b-o');

% t=(sum(sm_anti_o-sm_pro_o)/length(sm_anti_o-sm_pro_o))/ste(sm_anti_o-sm_pro_o)
% p=(1-tcdf(abs(t),length(sm_pro_o)-1))*2
% text(.5,.75,['p=' num2str(p)],'units','normalized')
[Hc,Pcent,CI,STATS] = TTEST(mean(anti_pro_cent,2))
[Hp,p_peri00,CI,STATS] = TTEST(anti_pro_peri(:,1))
[Hp,p_peri05,CI,STATS] = TTEST(anti_pro_peri(:,2))
[Hp,p_peri10,CI,STATS] = TTEST(anti_pro_peri(:,3))
[Hp,p_cent00,CI,STATS] = TTEST(anti_pro_cent(:,1))
[Hp,p_cent05,CI,STATS] = TTEST(anti_pro_cent(:,2))
[Hp,p_cent10,CI,STATS] = TTEST(anti_pro_cent(:,3))

% t=(sum(anti_pro_peri(:,1))/length(anti_pro_peri(:,1)))/ste(anti_pro_peri(:,1));
% p_peri00=(1-tcdf(abs(t),length(anti_pro_peri(:,1))-1))*2;
text(0,575,['p=' num2str(p_peri00)])
% t=(sum(anti_pro_peri(:,2))/length(anti_pro_peri(:,2)))/ste(anti_pro_peri(:,2));
% p_peri05=(1-tcdf(abs(t),length(anti_pro_peri(:,1))-1))*2
text(.5,575,['p=' num2str(p_peri05)])
% t=(sum(anti_pro_peri(:,3))/length(anti_pro_peri(:,3)))/ste(anti_pro_peri(:,3));
% p_peri10=(1-tcdf(abs(t),length(anti_pro_peri(:,1))-1))*2
text(1,575,['p=' num2str(p_peri10)])

subplot(2,1,2);hold on;set(gca,'XTick',[0:.5:1]);title('Central')
errorbar(0:.5:1,temp1(3,:),temp2(3,:),'r-s');
errorbar(0:.5:1,temp1(4,:),temp2(4,:),'b-o');

p_cent=(1-tcdf(abs(mean(anti_pro_cent(2:end,:))./ste(anti_pro_cent(2:end,:))),sub_num-1))*2
p_peri=(1-tcdf(abs(mean(anti_pro_peri(2:end,:))./ste(anti_pro_peri(2:end,:))),sub_num-1))*2



t=(sum(anti_pro_cent(:,1))/length(anti_pro_cent(:,1)))/ste(anti_pro_cent(:,1));
p_cent00=(1-tcdf(abs(t),length(anti_pro_cent(:,1))-1))*2
text(0,575,['p=' num2str(p_cent00)])
t=(sum(anti_pro_cent(:,2))/length(anti_pro_cent(:,2)))/ste(anti_pro_cent(:,2));
p_cent05=(1-tcdf(abs(t),length(anti_pro_cent(:,1))-1))*2
text(.5,575,['p=' num2str(p_cent05)])
t=(sum(anti_pro_cent(:,3))/length(anti_pro_cent(:,3)))/ste(anti_pro_cent(:,3));
p_cent10=(1-tcdf(abs(t),length(anti_pro_cent(:,1))-1))*2
text(1,575,['p=' num2str(p_cent10)])

mean(anti_pro_peri)
mean(anti_pro_cent)

fig(3+fig_adj);clf; set(gcf,'name',fig_names)

temp1=mean(gapfred,3);
temp2=ste(gapfred,0,3);
subplot(2,1,1);hold on;set(gca,'XTick',[0:.5:1]);title('Peripherial')
errorbar(1,temp1(1),temp2(1),'r-s');
errorbar(1,temp1(2),temp2(2),'b-o');

t=(sum(gap_anti_pro_peri)/length(gap_anti_pro_peri))/ste(gap_anti_pro_peri);
p_perigap=(1-tcdf(abs(t),length(gap_anti_pro_peri)-1))*2;
text(.5,.75,['p=' num2str(p_peri00)],'units','normalized')

subplot(2,1,2);hold on;set(gca,'XTick',[0:.5:1]);title('Central')
errorbar(1,temp1(3),temp2(3),'r-s');
errorbar(1,temp1(4),temp2(4),'b-o');
t=(sum(gap_anti_pro_cent)/length(gap_anti_pro_cent))/ste(gap_anti_pro_cent);
p_centgap=(1-tcdf(abs(t),length(gap_anti_pro_cent)-1))*2;
text(.5,.75,['p=' num2str(p_cent00)],'units','normalized')

p_gap_cent=(1-tcdf(abs(mean(gap_anti_pro_cent)./ste(gap_anti_pro_cent)),sub_num-1))*2
p_gap_peri=(1-tcdf(abs(mean(gap_anti_pro_peri)./ste(gap_anti_pro_peri)),sub_num-1))*2

[Hc,Pcent,CI,STATS] = TTEST(mean(anti_pro_cent,2))
[Hp,Pperi,CI,STATS] = TTEST(mean(anti_pro_peri,2))

antiperi00=mean(bigfred(1,1,:));%
properi00=mean(bigfred(2,1,:));%
anticent00=mean(bigfred(3,1,:));%
procent00=mean(bigfred(4,1,:));%

antiperi05=mean(bigfred(1,2,:));%
properi05=mean(bigfred(2,2,:));%
anticent05=mean(bigfred(3,2,:));%
procent05=mean(bigfred(4,2,:));%

antiperi10=mean(bigfred(1,3,:));%
properi10=mean(bigfred(2,3,:));%
anticent10=mean(bigfred(3,3,:));%
procent10=mean(bigfred(4,3,:));%
fig(4+fig_adj);clf; hold on;set(gcf,'name',fig_names);
plot(0:.5:1,[antiperi00 antiperi05 antiperi10],'-or');
plot(0:.5:1,[properi00 properi05 properi10],'-ob');
plot(0:.5:1,[anticent00 anticent05 anticent10],'-om');
plot(0:.5:1,[procent00 procent05 procent10],'-oc');
